home *** CD-ROM | disk | FTP | other *** search
/ Aminet 49 / Aminet 49 (2002)(GTI - Schatztruhe)[!][Jun 2002].iso / Aminet / dev / misc / FlexCat.lha / Lib / C_c_V20.sd < prev    next >
Text File  |  1999-11-28  |  6KB  |  208 lines

  1. ##rem $Id: C_c_V20.sd,v 1.2 1999/11/28 03:36:41 carlos Exp $
  2. ##stringtype C
  3. ##shortstrings
  4. /****************************************************************
  5.    This file was created automatically by `%fv'
  6.    from "%f0".
  7.  
  8.    Do NOT edit by hand!
  9. ****************************************************************/
  10.  
  11. #include <string.h>
  12.  
  13. #include <exec/memory.h>
  14. #include <libraries/iffparse.h>
  15.  
  16.  
  17. #if defined(__SASC)  ||  defined(_DCC)
  18. #include <proto/exec.h>
  19. #include <proto/dos.h>
  20. #include <proto/utility.h>
  21. #include <proto/iffparse.h>
  22. #include <proto/locale.h>
  23. #elif defined(__GNUC__)
  24. #include <inline/locale.h>
  25. #include <inline/iffparse.h>
  26. #include <inline/dos.h>
  27. #include <inline/exec.h>
  28. #include <inline/utility.h>
  29. #else
  30. #include <clib/iffparse_protos.h>
  31. #include <clib/locale_protos.h>
  32. #include <clib/dos_protos.h>
  33. #include <clib/exec_protos.h>
  34. #include <clib/utility_protos.h>
  35. #endif
  36.  
  37.  
  38.  
  39.  
  40.  
  41. static LONG %b_Version = %v;
  42. static const STRPTR %b_BuiltInLanguage = (STRPTR) %l;
  43.  
  44. struct FC_Type
  45. {   LONG    ID;
  46.     STRPTR  Str;
  47. };
  48.  
  49. const struct FC_Type _%i = { %d, %s };
  50.  
  51. static struct Catalog *%b_Catalog = NULL;
  52. static struct FC_Type *%b_OwnCatalog = NULL;
  53. static LONG %b_OwnStrings;
  54. static LONG %b_OwnBytes;
  55.  
  56. void Open%bCatalog(struct Locale *loc, STRPTR language)
  57. { LONG tag, tagarg;
  58.   extern struct Library *LocaleBase;
  59.   extern struct Library *IFFParseBase;
  60.   extern void Close%bCatalog(void);
  61.  
  62.   Close%bCatalog();  /*  Not needed if the programmer pairs Open-()
  63.                          and CloseCatalog() right, but does no harm. */
  64.   if (language == NULL)
  65.   { tag = TAG_IGNORE;
  66.   }
  67.   else
  68.   { tag = OC_Language;
  69.     tagarg = (LONG) language;
  70.   }
  71.   if (LocaleBase != NULL  &&  %b_Catalog == NULL)
  72.   { %b_Catalog = OpenCatalog(loc, (STRPTR) "%b.catalog",
  73.                              OC_BuiltInLanguage, %b_BuiltInLanguage,
  74.                              tag, tagarg,
  75.                              OC_Version, %b_Version,
  76.                              TAG_DONE);
  77.   }
  78.   if (LocaleBase == NULL  &&  IFFParseBase != NULL  &&  language != NULL  &&
  79.       Stricmp(language, %b_BuiltInLanguage) != 0)
  80.   { struct IFFHandle *iffhandle;
  81.     char path[128]; /*  Enough to hold 4 path items (dos.library 3.0)  */
  82.  
  83.     if ((iffhandle = AllocIFF())  !=  NULL)
  84.     { /*  Trying to open the catalog  */
  85.       strcpy(path, "Catalogs");
  86.       AddPart((STRPTR) path, language, sizeof(path));
  87.       AddPart((STRPTR) path, (STRPTR) "%b.catalog", sizeof(path));
  88.       if ((iffhandle->iff_Stream = Open((STRPTR) path, MODE_OLDFILE))
  89.                                  ==  NULL)
  90.       { strcpy(path, "Locale:Catalogs");
  91.         AddPart((STRPTR) path, language, sizeof(path));
  92.         AddPart((STRPTR) path, (STRPTR) "%b.catalog", sizeof(path));
  93.         iffhandle->iff_Stream = Open((STRPTR) path, MODE_OLDFILE);
  94.       }
  95.  
  96.       if (iffhandle->iff_Stream)
  97.       { InitIFFasDOS(iffhandle);
  98.         if (!OpenIFF(iffhandle, IFFF_READ))
  99.         { if (!PropChunk(iffhandle, MAKE_ID('C','T','L','G'),
  100.                          MAKE_ID('S','T','R','S')))
  101.           { struct StoredProperty *sp;
  102.             int error;
  103.  
  104.             for (;;)
  105.             { if ((error = ParseIFF(iffhandle, IFFPARSE_STEP))
  106.                          ==  IFFERR_EOC)
  107.               { continue;
  108.               }
  109.               if (error != 0)
  110.               { break;
  111.               }
  112.  
  113.               if (sp = FindProp(iffhandle, MAKE_ID('C','T','L','G'),
  114.                                 MAKE_ID('S','T','R','S')))
  115.               { LONG *ptr;
  116.                 LONG BytesToScan, StrLength;
  117.  
  118.                 /*  First scan: Check the number of strings             */
  119.                 /*  Note that this assumes that the strings are padded  */
  120.                 /*  to a longword boundary!                             */
  121.                 %b_OwnBytes = 0;
  122.                 %b_OwnStrings = 0;
  123.                 BytesToScan = sp->sp_Size;
  124.                 ptr = sp->sp_Data;
  125.                 while (BytesToScan > 0)
  126.                 { ++%b_OwnStrings;
  127.                   ++ptr;                      /*  Skip ID               */
  128.                   StrLength = *ptr+1;         /*  NUL-Byte!             */
  129.                   %b_OwnBytes += StrLength;
  130.                   ptr += 1+(StrLength+3)/4;   /*  Skip Length and String*/
  131.                   BytesToScan -= 8+((StrLength+3)/4)*4;
  132.                 }
  133.  
  134.                 /*  Marginal check: BytesToScan has to be 0!            */
  135.                 if (BytesToScan == 0)
  136.                 { char *cptr;
  137.                   LONG i;
  138.  
  139.                   if (%b_OwnCatalog = (struct FC_Type *)
  140.                       AllocMem(%b_OwnStrings*sizeof(struct FC_Type)+%b_OwnBytes,
  141.                                MEMF_ANY))
  142.                   { /*  Second scan: Copy the strings and their ID's    */
  143.                     cptr = (char *) &%b_OwnCatalog[%b_OwnStrings];
  144.                     BytesToScan = sp->sp_Size;
  145.                     ptr = sp->sp_Data;
  146.                     i = 0;
  147.                     while (BytesToScan > 0)
  148.                     { %b_OwnCatalog[i].ID = *(ptr++);
  149.                       %b_OwnCatalog[i].Str = (STRPTR) cptr;
  150.                       StrLength = *ptr+1;     /*  NUL-Byte!             */
  151.                       ptr++;
  152.                       strncpy(cptr, (char *) ptr, StrLength);
  153.                                         /*  Not more, not less bytes!   */
  154.                       cptr+=StrLength;
  155.                       ptr += (StrLength+3)/4;
  156.                       BytesToScan -= 8+((StrLength+3)/4)*4;
  157.                       ++i;
  158.                     }
  159.                     break;
  160.                   }
  161.                 }
  162.               }
  163.             }
  164.           }
  165.           CloseIFF(iffhandle);
  166.         }
  167.         Close(iffhandle->iff_Stream);
  168.       }
  169.  
  170.       FreeIFF(iffhandle);
  171.     }
  172.   }
  173. }
  174.  
  175.  
  176. void Close%bCatalog(void)
  177. { if (LocaleBase != NULL)
  178.   { CloseCatalog(%b_Catalog);
  179.   }
  180.   %b_Catalog = NULL;
  181.   if (%b_OwnCatalog != NULL)
  182.   { FreeMem(%b_OwnCatalog,
  183.             %b_OwnStrings*sizeof(struct FC_Type)+%b_OwnBytes);
  184.     %b_OwnCatalog = NULL;
  185.   }
  186. }
  187.  
  188.  
  189. STRPTR Get%bString(APTR fcstr)
  190. { STRPTR defaultstr = NULL;
  191.   LONG strnum, i;
  192.  
  193.   strnum = ((struct FC_Type *) fcstr)->ID;
  194.   defaultstr = ((struct FC_Type *) fcstr)->Str;
  195.  
  196.   if (%b_Catalog == NULL)
  197.   { if (%b_OwnCatalog != NULL)
  198.     { for (i = 0;  i < %b_OwnStrings;  i++)
  199.        { if (%b_OwnCatalog[i].ID == strnum)
  200.          { return(%b_OwnCatalog[i].Str);
  201.          }
  202.        }
  203.     }
  204.     return(defaultstr);
  205.   }
  206.   return(GetCatalogStr(%b_Catalog, strnum, defaultstr));
  207. }
  208.